// playground.entity.ts
import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  UpdateDateColumn,
  ManyToOne,
  BeforeInsert,
  BeforeUpdate,
} from 'typeorm';
import { Gymnasium } from 'src/modules/gymnasium/entities/gymnasium.entity';

@Entity('playground')
export class Playground {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  name: string;

  @ManyToOne(() => Gymnasium, (gymnasium) => gymnasium.playgrounds)
  gymnasium: Gymnasium;

  @Column()
  createBy: number;

  @CreateDateColumn()
  createTime: Date;

  @Column()
  updateBy: number;

  @UpdateDateColumn()
  updateTime: Date;

  @BeforeInsert()
  BeforeInsert() {
    this.createTime = new Date();
    this.updateTime = this.createTime;
  }

  @BeforeUpdate()
  BeforeUpdate() {
    this.updateTime = new Date();
  }
}
